package com.acme.bankapp.domain.bank;

/**
 * Constructor expects nonNegative balance
 * @author Java Student
 *
 */
public abstract class AbstractAccount {

	protected double balance;
	protected Client client;

	public Client getClient() {
		return client;
	}

	public void setClient(Client client) {
		this.client = client;
	}

	public AbstractAccount(double balance) throws IllegalArgumentException {
		if (balance < 0)
			throw new IllegalArgumentException("Negative balance");
		this.balance = balance;
	}

	public double getBalance() {
		return this.balance;
	}

	public void deposite(double amount) {
		this.balance += amount;
	}
	
	/**
	 * @return round balance value
	 */
	public long desimalValue() {
		return Math.round(this.getBalance());
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		long temp;
		temp = Double.doubleToLongBits(balance);
		result = prime * result + (int) (temp ^ (temp >>> 32));
		result = prime * result + ((client == null) ? 0 : client.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		AbstractAccount other = (AbstractAccount) obj;
		if (Double.doubleToLongBits(balance) != Double.doubleToLongBits(other.getBalance()))
			return false;
		if (client == null) {
			if (other.getClient() != null)
				return false;
		} else if (!client.equals(other.getClient()))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "AbstractAccount[balance=" + balance + "]";
	}
	
	

}